using UnityEngine;
using System.Collections;

public class SpawnAliens : MonoBehaviour {
	
	public Transform alien;
	public int random;
	public static int numAliens = 0;
	public float clock;
	
	void Start()
	{
		random = Random.Range(1,5);
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(Connection.playersConnected)
		{
			clock += Time.deltaTime;
			
			if(clock > random && numAliens < 15)
			{
				Network.Instantiate(alien, new Vector3(transform.position.x, transform.position.y + 0.1f, transform.position.z), Quaternion.identity, 0);
				numAliens++;
				random = Random.Range(1,5);
				clock = 0;
			}
			
			if(numAliens >= 15)
			{
				clock = 0;
			}
		}
	}
}
